﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SHNOPData.SHNOPModel;
namespace SHNOPData.common
{
    public  class OperateLogWrite
    {
        public static string operate="";
           
        public static void AnalysisNTPlanDetail(NTPlanDetail oldNTPlanDetail, NTPlanDetail newNTPlanDetail)
        {
            List<NTPlanDetail> list = new List<NTPlanDetail>();
            list.Add(oldNTPlanDetail);
            list.Add(newNTPlanDetail);
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(CompareNTPlanDetail));
            thread.Start(list);
        }

        #region 比较修改前后的站点详细信息 添加日志
        /// <summary>
        ///  比较修改前后的站点详细信息
        /// </summary>
        /// <param name="oldNTPlanDetail"></param>
        /// <param name="newNTPlanDetail"></param>
        public static void CompareNTPlanDetail(object obj)
        {
            List<NTPlanDetail> list = obj as List<NTPlanDetail>;
            NTPlanDetail oldNTPlanDetail = list[0];
            NTPlanDetail newNTPlanDetail = list[1];

            NTPlanBase newNtPlanBase = newNTPlanDetail.ntPlanBase;
            ZhanDianInfo newZhanDianInfo = newNTPlanDetail.zhanDianInfo;
            PortInfo newPortInfo = newNTPlanDetail.portInfo;
            PinLvInfo newPinLvInfo = newNTPlanDetail.pinLvInfo;
            InNetInfo newInNetInfo = newNTPlanDetail.inNetInfo;

            NTPlanBase oldNtPlanBase = oldNTPlanDetail.ntPlanBase;
            ZhanDianInfo oldZhanDianInfo = oldNTPlanDetail.zhanDianInfo;
            PortInfo oldPortInfo = oldNTPlanDetail.portInfo;
            PinLvInfo oldPinLvInfo = oldNTPlanDetail.pinLvInfo;
            InNetInfo oldInNetInfo = oldNTPlanDetail.inNetInfo;

           
            string ntPlanRemark = NTPlanDetailCompare.CompareNTPlanBase(oldNtPlanBase, newNtPlanBase);
            LogInfo loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.网络规划, newNtPlanBase.ntplanID, LogAction.修改, ntPlanRemark);
            AppDBMng.AddOperateLog(loginfo);
            if (oldZhanDianInfo == null || oldZhanDianInfo.zhanDianID == Guid.Empty)
            {
                if (newZhanDianInfo != null)
                {
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.站点, newZhanDianInfo.zhanDianID, LogAction.新增, "新增一条站点记录");
                }
            }
            else
            {
                if (newZhanDianInfo != null)
                {
                    string zhanDianRemark = NTPlanDetailCompare.CompareZhanDianInfo(oldZhanDianInfo, newZhanDianInfo);
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.站点, newZhanDianInfo.zhanDianID, LogAction.修改, zhanDianRemark);
                }
            }
       
            AppDBMng.AddOperateLog(loginfo);

            if (oldPortInfo == null || oldPortInfo.duanKouID == Guid.Empty)
            {
                if (newPortInfo != null)
                {
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.端口, newPortInfo.duanKouID, LogAction.新增, "新增一条端口记录");
                }
            }
            else
            {
                if (newPortInfo != null)
                {
                    string portRemark = NTPlanDetailCompare.ComparePortInfo(oldPortInfo, newPortInfo);
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.端口, newPortInfo.duanKouID, LogAction.修改, portRemark);
                }
            }
            AppDBMng.AddOperateLog(loginfo);
            if (oldPinLvInfo == null || oldPinLvInfo.pinLvID == Guid.Empty)
            {
                if (newPinLvInfo != null)
                {
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.端口, newPinLvInfo.pinLvID, LogAction.新增, "新增一条端口记录");
                }
            }
            else
            {
                if (newPinLvInfo != null)
                {
                    string pinLvRemark = NTPlanDetailCompare.ComparePinLvInfo(oldPinLvInfo, newPinLvInfo);
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.频率, newPinLvInfo.pinLvID, LogAction.修改, pinLvRemark);
                }

            }

            AppDBMng.AddOperateLog(loginfo);
            if (oldInNetInfo==null||oldInNetInfo.ruWangID == Guid.Empty)
            {
                if (newInNetInfo!=null)
                {
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.入网, newInNetInfo.ruWangID, LogAction.新增, "新增一条端口记录");
                }
                
            }
            else
            {
                if (newInNetInfo != null)
                {
                    string inNetRemark = NTPlanDetailCompare.CompareInNetInfo(oldInNetInfo, newInNetInfo);
                    loginfo = new LogInfo(operate, newNtPlanBase.ntplanID, OperateType.入网, newInNetInfo.ruWangID, LogAction.修改, inNetRemark);
                }
                
            }
            AppDBMng.AddOperateLog(loginfo);
        }
        #endregion
    

        #region 网络规划日志记录
        public static void LogNTPlanBase(object obj)
        {
               LogInfo loginfo = null;
               if (obj is NTPlanBase)
              {
                  NTPlanBase zd = obj as NTPlanBase;
                  loginfo = new LogInfo(operate, zd.ntplanID, OperateType.网络规划, zd.ntplanID, LogAction.导入, "批量导入一条网络规划记录");
              }
              else if (obj is List<NTPlanBase>)
               {
                   List<NTPlanBase> list = obj as List<NTPlanBase>;
                   NTPlanBase oldNTPlanBase = list[0];
                   NTPlanBase newNTPlanBase = list[1];
  
                   if (oldNTPlanBase != null && oldNTPlanBase.ntplanID.Equals(Guid.Empty))
                   {
                       string remark = NTPlanDetailCompare.CompareNTPlanBase(oldNTPlanBase, newNTPlanBase);
                       loginfo = new LogInfo(operate, newNTPlanBase.ntplanID, OperateType.网络规划, newNTPlanBase.ntplanID, LogAction.修改, remark);
                   }
                   else
                   {
                       loginfo = new LogInfo(operate, newNTPlanBase.ntplanID, OperateType.网络规划, newNTPlanBase.ntplanID, LogAction.新增, "新增一条网络规划记录");
                   }
               }
            AppDBMng.AddOperateLog(loginfo);
        }
        #endregion

        #region 站点日志记录
        public static void LogZhanDianInfo(object obj)
        {
            
              LogInfo loginfo = null;
              if (obj is ZhanDianInfo)
              {
                  ZhanDianInfo zd = obj as ZhanDianInfo;
                  loginfo = new LogInfo(operate, zd.guiHuaID, OperateType.站点, zd.zhanDianID, LogAction.导入, "批量导入一条站点记录");
              }
              else
              {
                  if (obj is List<ZhanDianInfo>)
                  {
                      List<ZhanDianInfo> list = obj as List<ZhanDianInfo>;
                      ZhanDianInfo oldZhanDianInfo = list[0];
                      ZhanDianInfo newZhanDianInfo = list[1];
                      if (oldZhanDianInfo != null && !oldZhanDianInfo.zhanDianID.Equals(Guid.Empty))
                      {
                          string remark = NTPlanDetailCompare.CompareZhanDianInfo(oldZhanDianInfo, newZhanDianInfo);
                          loginfo = new LogInfo(operate, newZhanDianInfo.guiHuaID, OperateType.站点, newZhanDianInfo.zhanDianID, LogAction.修改, remark);
                      }
                      else
                      {
                          loginfo = new LogInfo(operate, newZhanDianInfo.guiHuaID, OperateType.站点, newZhanDianInfo.zhanDianID, LogAction.新增, "新增一条站点记录");
                      }
                  }
              }
            AppDBMng.AddOperateLog(loginfo);
        }

        #endregion
        
        #region 端口日志记录
        public static void LogPortInfo(object obj)
        {
               LogInfo loginfo = null;
               if (obj is PortInfo)
               {
                   PortInfo port = obj as PortInfo;
                   loginfo = new LogInfo(operate, port.guiHuaID, OperateType.端口, port.duanKouID, LogAction.导入, "批量导入一条端口记录");
               }
               else if (obj is List<PortInfo>)
               {
                   List<PortInfo> list = obj as List<PortInfo>;
                   PortInfo oldPortInfo = list[0];
                   PortInfo newPortInfo = list[1];
                  
                   if (oldPortInfo != null && !oldPortInfo.duanKouID.Equals(Guid.Empty))
                   {
                       string remark = NTPlanDetailCompare.ComparePortInfo(oldPortInfo, newPortInfo);
                       loginfo = new LogInfo(operate, newPortInfo.guiHuaID, OperateType.端口, newPortInfo.duanKouID, LogAction.修改, remark);
                   }
                   else
                   {
                       loginfo = new LogInfo(operate, newPortInfo.guiHuaID, OperateType.端口, newPortInfo.duanKouID, LogAction.新增, "新增一条端口记录");
                   }
               }
            AppDBMng.AddOperateLog(loginfo);
        }
        #endregion

         #region 频率日志记录
        public static void LogPinLvInfo(object obj)
        {
             LogInfo loginfo = null;
             if (obj is PinLvInfo)
             {
                 PinLvInfo pinLv = obj as PinLvInfo;
                 loginfo = new LogInfo(operate, pinLv.guiHuaID, OperateType.频率, pinLv.pinLvID, LogAction.导入, "批量导入一条频率记录");
             }
             else if (obj is List<PinLvInfo>)
             {
                 List<PinLvInfo> list = obj as List<PinLvInfo>;
                 PinLvInfo oldPinLvInfo = list[0];
                 PinLvInfo newPinLvInfo = list[1];

                 if (oldPinLvInfo != null && !oldPinLvInfo.pinLvID.Equals(Guid.Empty))
                 {
                     string remark = NTPlanDetailCompare.ComparePinLvInfo(oldPinLvInfo, newPinLvInfo);
                     loginfo = new LogInfo(operate, newPinLvInfo.guiHuaID, OperateType.频率, newPinLvInfo.pinLvID, LogAction.修改, remark);
                 }
                 else
                 {
                     loginfo = new LogInfo(operate, newPinLvInfo.guiHuaID, OperateType.频率, newPinLvInfo.pinLvID, LogAction.新增, "新增一条频率记录");
                 }
             }
            AppDBMng.AddOperateLog(loginfo);
        }
        #endregion

        #region 入网日志记录
        public static void LogInNetInfo(object obj)
        {
            LogInfo loginfo = null;
            if (obj is InNetInfo)
            {
                InNetInfo inNet = obj as InNetInfo;
                loginfo = new LogInfo(operate, inNet.guiHuaID, OperateType.入网, inNet.ruWangID, LogAction.导入, "批量导入一条入网记录");
            }
            else if (obj is List<InNetInfo>)
            {
                List<InNetInfo> list = obj as List<InNetInfo>;
                InNetInfo oldInNetInfo = list[0];
                InNetInfo newInNetInfo = list[1];
              
                if (oldInNetInfo != null && !oldInNetInfo.ruWangID.Equals(Guid.Empty))
                {
                    string remark = NTPlanDetailCompare.CompareInNetInfo(oldInNetInfo, newInNetInfo);
                    loginfo = new LogInfo(operate, newInNetInfo.guiHuaID, OperateType.入网, newInNetInfo.ruWangID, LogAction.修改, remark);
                }
                else
                {
                    loginfo = new LogInfo(operate, newInNetInfo.guiHuaID, OperateType.入网, newInNetInfo.ruWangID, LogAction.新增, "新增一条入网记录");
                }
            }
       
           
       
            AppDBMng.AddOperateLog(loginfo);
        }
        #endregion
    }
}
